package com.order.manager.controller.Evaluate;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.order.manager.Model.ShopExamineInfo;
import com.order.manager.Model.other.RestBean;
import com.order.manager.service.impl.ShopExamineInfoServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RequestMapping("/api/examineShop")
@RestController
public class ShopExamineInfoController {

    @Resource
    ShopExamineInfoServiceImpl shopExamineInfoService;

    @RequestMapping("/apply")
    public RestBean shopExamineInfoApply(@RequestBody ShopExamineInfo shopExamineInfo) {
        shopExamineInfo.setInputTime(new Date());
        if (shopExamineInfoService.count(new QueryWrapper<ShopExamineInfo>().eq("shop_id", shopExamineInfo.getShopId())) != 0) {
            return shopExamineInfoService.updateById(shopExamineInfo) ? RestBean.success(shopExamineInfo) : RestBean.failure(500, "店铺审核信息更新失败");
        }
        return shopExamineInfoService.save(shopExamineInfo) ? RestBean.success(shopExamineInfo) : RestBean.failure(500, "店铺审核信息保存失败");
    }

    @RequestMapping("/get/{shopId}")
    public RestBean shopExamineInfoGet(@PathVariable String shopId) {
        ShopExamineInfo shopExamineInfoServiceById = shopExamineInfoService.getById(shopId);
        return shopExamineInfoServiceById != null ? RestBean.success(shopExamineInfoServiceById) :
                RestBean.failure(403, "不存在该店铺审核信息");
    }

}
